import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class person {
    //mysql地址，端口3306，数据库tms_db
    public static final String URL = "jdbc:mysql://localhost:3306/tms_db";
    public static final String USER = "root";
    public static final String PASSWORD = "1423";

    // 连接数据库
    public static Connection getConnection() {
        try {
            Class.forName("com.mysql.jdbc.Driver");
            Connection db_conn = DriverManager.getConnection(URL, USER, PASSWORD);
            return db_conn;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    public static void main(String[] args) throws Exception {
        Connection conn = null;
        //建立连接
        conn = getConnection();
        if (conn == null) {
            System.out.println("Error in Connection!");
            return;
        }

        Statement stmt = conn.createStatement();

        // 插入
        stmt.execute("INSERT INTO person (id, name, age,birthday) VALUES\n" +
                "(3,\"盖亚\",20,\"2000-05-01\")");

        // 修改
        stmt.execute("UPDATE person SET age = 30  WHERE id = 3");

        // 查找
        ResultSet rs = stmt.executeQuery("SELECT * FROM person");
        while (rs.next()) {
            System.out
                    .println("ID: " + rs.getInt("id") + ",name: " + rs.getString("name")
                            + ",age: " + rs.getInt("age") + ",birthday: " + rs.getString("birthday"));
        }

        // 删除
        stmt.execute("DELETE FROM person where id = 3");
    }
}